#ifndef __TwWater_H__
#define __TwWater_H__

#include "TwD3DHeaders.h"
#include "TwTexture.h"
#include "TwRenderable.h"

class TwShaderWater;
class TwCamera;

class TwWater : public TwRenderable
{
	friend class TwShaderWater;

public:
	struct VERTEX
	{
		D3DXVECTOR3 pos;
		float u, v;

		static const DWORD FVF = D3DFVF_XYZ | D3DFVF_TEX1;
	};

public:
	TwWater();
	virtual ~TwWater();

	bool create(const D3DXVECTOR3& pos, float width, float length);
	bool beginScene(TwCamera* camera);
	void endScene(TwCamera* camera);
	
	virtual void render(TwCamera* camera, TimeValue t);
	void drawPrimitive();
	bool InitShader();

protected:
	bool createShader();

protected:
	TwShaderWater*		mShader;

	TwTexture			mWaveTex;
	
	IDirect3DTexture9*	mEnvTex;
	IDirect3DSurface9*	mEnvSurface;
	IDirect3DSurface9*	mOldSurface;

	D3DXPLANE			mPlane;
	D3DXVECTOR3			mPos;
	float				mWidth;
	float				mLength;

	VERTEX				mVertices[4];
};

#endif //__TwWater_H__